#include "ex16_62.h"

Sales_data::Sales_data(std::istream &is) { is >> *this; }

Sales_data &Sales_data::operator+=(const Sales_data &s) {
  units_sold += s.units_sold;
  revenue += s.revenue;
  return *this;
}

std::ostream &operator<<(std::ostream &os, const Sales_data &s) {
  os << s.isbn() << " " << s.units_sold << " " << s.revenue << " "
     << s.avg_price();
  return os;
}

std::istream &operator>>(std::istream &is, Sales_data &s) {
  double price;
  is >> s.bookNo >> s.units_sold >> price;
  if (is)
    s.revenue = s.units_sold * price;
  else
    s = Sales_data();
  return is;
}

bool operator==(const Sales_data &ls, const Sales_data &rs) {
  return ls.bookNo == rs.bookNo && ls.units_sold == rs.units_sold &&
         ls.revenue == rs.revenue;
}
bool operator!=(const Sales_data &ls, const Sales_data &rs) {
  return !(ls == rs);
}

Sales_data operator+(const Sales_data &ls, const Sales_data &rs) {
  Sales_data temp = ls;
  temp += rs;
  return temp;
}

Sales_data add(const Sales_data &ls, const Sales_data &rs) {
  Sales_data temp = ls;
  temp += rs;
  return temp;
}

std::ostream &print(std::ostream &os, const Sales_data &s) {
  os << s.isbn() << " " << s.units_sold << " " << s.revenue << " "
     << s.avg_price();
  return os;
}

std::istream &read(std::istream &is, Sales_data &s) {
  double price;
  is >> s.bookNo >> s.units_sold >> price;
  s.revenue = s.units_sold * price;
  return is;
}